package com.xuecheng.learning.controller;

import com.xuecheng.api.learning.CourseRecordApi;
import com.xuecheng.api.learning.model.dto.CourseRecordDTO;
import com.xuecheng.api.media.model.vo.ResourceUrlModel;
import com.xuecheng.learning.common.utils.UAASecurityUtil;
import com.xuecheng.learning.service.CourseRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 选课记录 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseRecordController implements CourseRecordApi {

    @Autowired
    private CourseRecordService courseRecordService;


    @Override
    /*
     * 查询用户某课程记录(获取某课程学习进度)
     */
    @GetMapping("learnedRecords/myCourseRec/{coursePubId}")
    public CourseRecordDTO getRecordByCoursePubId(@PathVariable Long coursePubId) {
        String username = UAASecurityUtil.getUser().getUsername();
        CourseRecordDTO recordDTO = this.courseRecordService.getRecordByCoursePubId(coursePubId, username);
        return recordDTO;
    }

    @Override
    @GetMapping("resource-url")
    public ResourceUrlModel playUrl(Long coursePubId, Long teachplanId, Long mediaId) {
        String username = UAASecurityUtil.getUser().getUsername();
        ResourceUrlModel resourceUrlModel1 = this.courseRecordService.playUrl(coursePubId, teachplanId, mediaId,username);
        return resourceUrlModel1;
    }
}
